package databinding;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import model.Sach;
import model.TheLoai;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Execution;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Sessions;
import org.zkoss.zk.ui.select.SelectorComposer;

import dao.DatabaseConnector;
import dao.entity.SachDAO;

public class ProductViewModel {

	public List<Sach> getlistSach() {
		TheLoai theLoai = (TheLoai) Sessions.getCurrent().getAttribute("theloai");
//		Execution ex = Executions.getCurrent();
//		String idTheLoai = ex.getParameter("target");
		
//		TheLoai theloai = new TheLoai(Integer.parseInt(idTheLoai));
		SachDAO dao = new SachDAO();
		List<Sach> listSach = dao.findByCriteria(Restrictions.eq("theLoai",
				theLoai));
		return listSach;
	}

	public static void main(String[] args) {
		SachDAO dao = new SachDAO();
		TheLoai theloai = new TheLoai(1);
		List<Sach> list = dao.findByCriteria(Restrictions
				.eq("theLoai", theloai));
		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i).getTenSach());
		}
	}

}
